package com.wf.LeetCode;

/**
 * @author mpk
 * @since 2024/6/11 20:48:41
 */
public class IsPrefixOfWord {
    public static void main(String[] args) {

        String sentence = "this problem is an easy problem";
        String searchWord = "pro";
        System.out.println(isPrefixOfWord(sentence, searchWord));
    }


    public static int isPrefixOfWord(String sentence, String searchWord) {


        String[] strings = sentence.split(" ");


        for (int i = 0; i < strings.length; i++) {

            if (strings[i].startsWith(searchWord)) {
                return i + 1;
            }
        }

        return -1;
    }

}
